<template>
    <div>
      <h2>Loin</h2>

      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
        <el-form-item label="账号：" prop="username">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码：" prop="password">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>


    </div>
</template>

<script>
    import login from '@/views/login/login.js'
    export default login
    /*{
        name: "Login",
      data(){
          return {
            form:{
              username:'emp',
              password:'123456'
            },
            rules: {
              username:[
                { required: true, message: '请输入账号', trigger: 'blur' },
                { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
              ],
              password:[
                { required: true, message: '请输入密码', trigger: 'blur' },
              ]
            }
          }
      },
        mounted() {
          console.log(location.hash);
          /!*sessionStorage.JWTHeaderName = 'JWTHeaderName'*!/
        },
      methods:{
        onSubmit: function () {
          this.$refs['form'].validate( valid =>  valid ? (this.auth(),true): (console.log('error submit!!'),false) )
        },
        auth(){
          console.log('asdas',this.form)
         let formData = new FormData()
          for (let key in this.form) formData.append(key, this.form[key])
          this.$axios.post('/jwtLogin',this.form).then(res =>(
            res.code==200 && res.isok ? (
              console.log(res),
              sessionStorage.JWTHeaderName = res.data.JWTHeaderName,
              this.$router.replace("/home")
            ):res.code==401 && !res.isok? (console.log(res),this.errormsg(res.message)):''
          )).catch(error => console.log(error))
        },
        errormsg(str){
          this.$confirm(str, '提示', {
            confirmButtonText: '确定',
            type: 'warning',
            showCancelButton:false
          })
        }
      }
    }*/
</script>

<style scoped>

</style>
